<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新闻发布列表</title>
    <script th:src="@{/js/jquery/jquery-3.6.0.js}" type="text/javascript"></script>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <script type="text/javascript" src="/xadmin/js/xadmin.js"></script>

    <link rel="stylesheet" th:href="@{/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{/xadmin/css/xadmin.css}"/>
    <link rel="stylesheet" th:href="@{/layui/css/modules/layer/default/layer.css}"/>

    <style type="text/css">
        .layui-table {
            text-align: center;
        }

        .layui-table th {
            text-align: center;
        }
    </style>
</head>
<body>

<div class="x-nav">
      <span>
        <a href="">首页&nbsp&nbsp  /</a>
        <a href="/back/article/permitPage">&nbsp&nbsp新闻发布列表</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="/back/article/permitPage"
       title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>


<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" action="/back/article/permitPage" >
            <input class="layui-input" placeholder="请输入用户账号" name="uname" >
            <input class="layui-input" placeholder="请输入分类名" name="cname" >
            <input class="layui-input" placeholder="请输入新闻标题名" name="title" >

<!--            <input class="layui-input" type="hidden" name="pageIndex" value="1">-->
<!--            <input class="layui-input" type="hidden" name="pageSize" value="20">-->
            <button class="layui-btn"  lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>

<!--    数据表格-->
    <table class="layui-table">
        <thead>
        <th>序号</th>
        <th>新闻标题</th>
        <th>新闻分类</th>
        <th>用户账号</th>
        <th>用户昵称</th>
        <th>发布时间</th>
        <th>文章等级</th>
        <th>操作</th>
        </thead>

        <tbody>

            <tr th:each="article,stat:${permitStatus.records}">
                <td th:text="${stat.count}">序号</td>
                <td th:text="${article.title}">新闻标题</td>
                <td th:text="${article.category.cname}">新闻分类</td>
                <td th:text="${article.user.uname}">用户账号</td>
                <td th:text="${article.user.newsName}">用户昵称</td>
                <td th:text="${#dates.format(article.createTime, 'yyyy-MM-dd HH:mm')}">发布时间</td>
                <td th:text="${article.lid}">文章等级</td>
                <td>
                    <a class="layui-btn layui-btn-xs" th:onclick="x_admin_show('查看新闻','/back/article/view?id=[[${article.id}]]')">查看</a>
                    <a class="layui-btn layui-btn-normal layui-btn-xs"  th:onclick="deny(this,[[${article.id}]])">不通过</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" th:onclick="del(this,[[${article.id}]])">删除</a>
                </td>
            </tr>
        </tbody>
    </table>

    <!--分页,默认第一页开始，一页20条数据-->
    <div id="pages">
        <div class="layui-box layui-laypage layui-laypage-default">
            <a  th:href="@{/back/article/permitPage(pn=${permitStatus.current}-1)}"
                th:class="${permitStatus.current==1?'layui-laypage-prev layui-disabled':''}" >上一页</a>

            <span th:class="layui-laypage-curr" th:if="${permitTotal} eq '1'">
                <em class="layui-laypage-em"></em><em>1</em>
            </span>

            <span th:if="${permitTotal} gt '1'" th:class="${num==permitStatus.current?'layui-laypage-curr':''}"
                  th:each="num:${#numbers.sequence(1,permitStatus.pages)}">
                <a th:href="@{/back/article/permitPage(pn=${num})}"><em class="layui-laypage-em"></em><em>[[${num}]]</em></a>
            </span>

            <a th:href="@{/back/article/permitPage(pn=${permitStatus.current}+1)}"
               th:class="${permitStatus.current==permitStatus.getPages()?'layui-laypage-next layui-disabled':''}">下一页</a>

            <span class="layui-laypage-count">当前第 [[${permitStatus.current}]] 页，总计 [[${permitStatus.pages}]] 页,
                共 [[${permitStatus.total}]] 条记录</span>
        </div>
    </div>
</div>


<script>
    //用户新闻删除
    function del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $.post("/back/article/deleteArticle",{"id":id},function (data) {
                if(data =='success'){
                    layer.msg('删除成功!',{icon:1,time:2000});
                    setTimeout(function () {window.location.href='/back/article/permitPage';},2000);

                }else {
                    layer.msg('删除失败!',{icon:0,time:2000});
                    setTimeout(function () {window.location.href='/back/article/permitPage';},2000);
                }
            });
        });
    }
    //用户新闻不通过
    function deny(obj,id){
        $.post("/back/article/deny",{"id":id},function (data) {
            if(data =='true'){
                layer.msg('操作成功：审核不通过!',{icon:1,time:2000});
                setTimeout(function () {window.location.href='/back/article/permitPage';},2000);

            }else {
                layer.msg('出现错误，请稍后再试!',{icon:0,time:2000});
                //  setTimeout(function () {window.location.href='/back/cate';},2000);
            }
        });
    }

</script>


</body>
</html>